package com.zp.qualitypractice.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.zp.qualitypractice.R;
import com.zp.qualitypractice.Utils.TimeUtils;
import com.zp.qualitypractice.Utils.ToastUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author izp on 2017/10/24.
 */

public class TestRxTimeUtilActivity extends AppCompatActivity {
    @BindView(R.id.tv_result)
    TextView tvResult;
    @BindView(R.id.btn_action)
    Button btnAction;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        ButterKnife.bind(this);
        btnAction.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ToastUtils.shortToast(TestRxTimeUtilActivity.this,"开始计时");
                TimeUtils.timer(2000, new TimeUtils.IRxNext() {
                    @Override
                    public void doNext(long number) {
                        ToastUtils.shortToast(TestRxTimeUtilActivity.this,"结束计时");
                        finish();
                    }
                });
            }
        });

    }

    @Override
    protected void onDestroy() {
        //取消定时器
        TimeUtils.cancel();
        super.onDestroy();
    }
}
